﻿using System;

namespace AppWorks.Domain.Events
{
    [Serializable]
    public abstract class Event : IEvent
    {
        private static Version DefaultVersion = new Version(1, 0);

        public Guid EventIdentifier { get; internal protected set; }

        public DateTime EventTimeStamp { get; internal protected set; }

        public Version EventVersion { get; internal protected set; }

        public Event()
        {
            var idGenerator = Environment.Get<IUniqueIdentifierGenerator>();
            var clock = Environment.Get<IClock>();

            EventIdentifier = idGenerator.GenerateNewId();
            EventTimeStamp = clock.UtcNow();
            EventVersion = DefaultVersion;
        }

        public Event(Guid eventIdentifier, DateTime eventTimeStamp)
            : this(eventIdentifier, eventTimeStamp, DefaultVersion)
        {
        }

        public Event(Guid eventIdentifier, DateTime eventTimeStamp, Version eventVersion)
        {
            EventIdentifier = eventIdentifier;
            EventTimeStamp = eventTimeStamp;
            EventVersion = eventVersion;
        }

        /// <summary>
        /// 应用[发布到事件中心]
        /// </summary>
        public void Apply()
        { }

        /// <summary>
        /// 事件回放
        /// </summary>
        public void Replay()
        { }
    }
}